package com.ptu.spzx.manager.controller;


import com.ptu.spzx.manager.service.DeptService;
import com.ptu.spzx.model.entity.system.SysDept;
import com.ptu.spzx.model.vo.common.Result;
import com.ptu.spzx.model.vo.common.ResultCodeEnum;
import com.ptu.spzx.model.vo.system.SysDeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/admin/system/sysDept")
public class SysDeptController {
    @Autowired
    private DeptService deptService;

    //删除部门接口
    @DeleteMapping("/removeById/{id}")
    public Result removeById(@PathVariable(value = "id") Long id){
        deptService.removeById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //更新部门接口
    @PutMapping("/update")
    public Result update(@RequestBody SysDept sysDept){
        deptService.update(sysDept);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //部门的添加
    @PostMapping("/save")
    public Result save(@RequestBody SysDept sysDept){
        deptService.save(sysDept);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //部门列表
    @GetMapping("/findNodes")
    public Result findNodes(){
        List<SysDeptVo> list=deptService.findNodes();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/findDeptAll")
    public List<SysDept> findDeptAll(){
        return deptService.findDeptAll();
    }
}
